package com.it.gmall.cart.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.it.gmall.cart.mapper.CartMapper;
import com.it.gmall.model.cart.CartInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class CartServiceAsyncImpl implements CartServiceAsync {
    @Autowired
    private CartMapper cartMapper;

    // 将购物车信息添加到DB中
    @Async
    @Override
    public void addCartInfoToDB(CartInfo cartInfo) {
        cartMapper.insert(cartInfo);
    }

    // 在DB中修改购物车信息
    @Async
    @Override
    public void updateCartInfoToDB(CartInfo cartInfo) {
        String userId = cartInfo.getUserId();
        Long skuId = cartInfo.getSkuId();
        // 根据用户id和商品 id修改数据
        cartMapper.update(cartInfo,new QueryWrapper<CartInfo>().eq("user_id",userId).eq("sku_id",skuId));
    }
}
